package hexagone;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import static java.awt.Color.*;
import static hexagone.utils.DoublePair.*;

public class Hexagone {

    private Graphics2D g;
    private int X;
    private int Y;
    private Double[] xchemin;
    private Double[] ychemin;
    float epaisseur = 2;
    float[] style = {10, 5};
    BasicStroke stroke = new BasicStroke(epaisseur, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0F, style, 0);
    int zoom = 20;
    int[] hexagone_1 = {1, 1, 1, 1, 1, 1};
    int[] hexagone_0 = {0, 0, 0, 0, 0, 0};

    public Hexagone(Graphics2D g) {
        this.g = g;
    }

    public void buildAndDraw(int[] nombre) {// {0, 1, 1, 0, 0, 1};

        xchemin = new Double[ 6 ];
        ychemin = new Double[ 6 ];
        for (int i = 0 ; i < nombre.length ; i++) {
            if (nombre[i] == 0) {
                xchemin[i] = zoom * R_1[i]._1() + X;
                ychemin[i] = zoom * R_1[i]._2() + Y;
            } else if (nombre[i] == 1) {
                xchemin[i] = zoom * R_2[i]._1() + X;
                ychemin[i] = zoom * R_2[i]._2() + Y;
            }
        }
        polygone(BLUE);

    }

    public void setPosition(int X, int Y) {
        this.X = X;
        this.Y = Y;
    }

    private void polygone(Color color) {
        g.setStroke(stroke);
        g.setColor(color);
        int[] xcheminIs = new int[ 6 ];
        int[] ycheminIs = new int[ 6 ];
        for (int k = 0 ; k < xchemin.length ; k++) {
            xcheminIs[k] = xchemin[k].intValue();
            ycheminIs[k] = ychemin[k].intValue();
        }
        g.drawPolygon(xcheminIs, ycheminIs, 6);
    }

    public void hexagone_1(Color color) {
        xchemin = new Double[ 6 ];
        ychemin = new Double[ 6 ];
        for (int i = 0 ; i < hexagone_1.length ; i++) {
            if (hexagone_1[i] == 0) {
                xchemin[i] = zoom * R_1[i]._1() + X;
                ychemin[i] = zoom * R_1[i]._2() + Y;
            } else if (hexagone_1[i] == 1) {
                xchemin[i] = zoom * R_2[i]._1() + X;
                ychemin[i] = zoom * R_2[i]._2() + Y;
            }

        }

        polygone(color);
    }

    public void hexagone_0(Color color) {
        xchemin = new Double[ 6 ];
        ychemin = new Double[ 6 ];
        for (int i = 0 ; i < hexagone_0.length ; i++) {
            if (hexagone_0[i] == 0) {
                xchemin[i] = zoom * R_1[i]._1() + X;
                ychemin[i] = zoom * R_1[i]._2() + Y;
            } else if (hexagone_0[i] == 1) {
                xchemin[i] = zoom * R_2[i]._1() + X;
                ychemin[i] = zoom * R_2[i]._2() + Y;
            }

        }

        polygone(color);
    }
}










